import request from '@/utils/request'

// 数据字典管理相关接口
export const cate = {
  // 获取数据字典列表
  getList: (params?: any) => {
    return request({
      url: '/api/home/cate/list',
      method: 'get',
      params,
    })
  },

  // 查看单个数据字典信息
  view: (id: number) => {
    return request({
      url: '/api/home/cate/view',
      method: 'get',
      params: { id },
    })
  },

  // 新建数据字典
  add: (data: any) => {
    return request({
      url: '/api/home/cate/add',
      method: 'post',
      data,
    })
  },

  // 编辑数据字典
  edit: (data: any) => {
    return request({
      url: '/api/home/cate/edit',
      method: 'put',
      data,
    })
  },

  // 删除数据字典
  delete: (id: number) => {
    return request({
      url: '/api/home/cate/del',
      method: 'delete',
      data: { id },
    })
  },

  // 获取启用的数据字典列表
  getActiveList: () => {
    return request({
      url: '/api/home/cate/set',
      method: 'get',
    })
  },

  // 设置数据字典状态
  setStatus: (data: { id: number; status: number }) => {
    return request({
      url: '/api/home/cate/set_status',
      method: 'post',
      data,
    })
  },

  // 企业主体相关接口
  // 获取企业主体列表
  getEnterpriseList: () => {
    return request({
      url: '/api/home/cate/enterprise/list',
      method: 'get',
    })
  },

  // 新建/编辑企业主体
  addEnterprise: (data: any) => {
    return request({
      url: '/api/home/cate/enterprise/add',
      method: 'post',
      data,
    })
  },

  // 编辑企业主体
  editEnterprise: (data: any) => {
    return request({
      url: '/api/home/cate/enterprise/edit',
      method: 'put',
      data,
    })
  },

  // 删除企业主体
  deleteEnterprise: (id: number) => {
    return request({
      url: '/api/home/cate/enterprise/del',
      method: 'delete',
      data: { id },
    })
  },

  // 查看企业主体详情
  viewEnterprise: (id: number) => {
    return request({
      url: '/api/home/cate/enterprise/view',
      method: 'get',
      params: { id },
    })
  },

  // 企业主体设置状态
  setEnterpriseStatus: (data: { id: number; status: number }) => {
    return request({
      url: '/api/home/cate/enterprise/set_status',
      method: 'post',
      data,
    })
  },

  // 企业主体设置（检查）
  checkEnterprise: () => {
    return request({
      url: '/api/home/cate/enterprise/check',
      method: 'get',
    })
  },
}

// 向后兼容方法
export const getCateList = cate.getList
export const viewCate = cate.view
export const addCate = cate.add
export const editCate = cate.edit
export const deleteCate = cate.delete
export const getActiveCateList = cate.getActiveList
export const setCateStatus = cate.setStatus

// 企业主体相关导出
export const getEnterpriseList = cate.getEnterpriseList
export const addEnterprise = cate.addEnterprise
export const editEnterprise = cate.editEnterprise
export const deleteEnterprise = cate.deleteEnterprise
export const viewEnterprise = cate.viewEnterprise
export const setEnterpriseStatus = cate.setEnterpriseStatus
export const checkEnterprise = cate.checkEnterprise

// 为了匹配 CateList.vue 中使用的函数名
export const saveEnterprise = (data: any) => {
  return data.id ? editEnterprise(data) : addEnterprise(data)
}
